{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "ec35011c",
   "metadata": {},
   "source": [
    "# PriorFactor\n",
    "\n",
    "## Overview\n",
    "\n",
    "The `PriorFactor` represents a prior belief about a variable in the form of a Gaussian distribution. This class is crucial for incorporating prior knowledge into the optimization process, which can significantly enhance the accuracy and robustness of the solutions.\n",
    "\n",
    "## Key Functionalities\n",
    "\n",
    "### PriorFactor Construction\n",
    "\n",
    "The `PriorFactor` is constructed by specifying a key, a prior value, and a noise model. The key identifies the variable in the factor graph, the prior value represents the expected value of the variable, and the noise model encapsulates the uncertainty associated with this prior belief.\n",
    "\n",
    "### Error Calculation\n",
    "\n",
    "The primary role of the `PriorFactor` is to compute the error between the estimated value of a variable and its prior. This error is typically defined as:\n",
    "\n",
    "$$\n",
    "e(x) = x - \\mu\n",
    "$$\n",
    "\n",
    "where $x$ is the estimated value, and $\\mu$ is the prior mean. The error is then weighted by the noise model to form the contribution of this factor to the overall objective function.\n",
    "\n",
    "### Adding to a Factor Graph\n",
    "\n",
    "[NonlinearFactorGraph](./NonlinearFactorGraph.ipynb) has a templated method `addPrior<T>` that provides a convenient way to add priors.\n",
    "\n",
    "## Usage Considerations\n",
    "\n",
    "- **Noise Model**: The choice of noise model is critical as it determines how strongly the prior is enforced. A tighter noise model implies a stronger belief in the prior. *Note that very strong priors might make the condition number of the linear systems to be solved very high. In this case consider adding a [NonlinearEqualityFactor]\n",
    "- **Integration with Other Factors**: The `PriorFactor` is typically used in conjunction with other factors that model the system dynamics and measurements. It helps anchor the solution, especially in scenarios with limited or noisy measurements.\n",
    "- **Applications**: Common applications include SLAM (Simultaneous Localization and Mapping), where priors on initial poses or landmarks can significantly improve map accuracy and convergence speed.\n",
    "\n",
    "## Conclusion\n",
    "\n",
    "The `PriorFactor` class is a fundamental component in GTSAM for incorporating prior information into the factor graph framework. By understanding its construction, error computation, and integration into the optimization process, users can effectively leverage prior knowledge to enhance their estimation and optimization tasks."
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
